<?php

namespace App\Http\Requests;

use Illuminate\Foundation\Http\FormRequest;

class UserRequest extends FormRequest
{
    /**
     * Determine if the user is authorized to make this request.
     *
     * @return bool
     */
    public function authorize()
    {
        return true;
    }

    /**
     * Get the validation rules that apply to the request.
     *
     * @return array
     */
    public function rules()
    {
        if ($this->isMethod('post')){
            return [
               // 'user_number'=>'required|unique:users_base,user_number|alpha_start',
                'real_name'=>'required',
                'user_phone'=>'required|mobile|unique:users_base,user_phone',
                'login_pwd'=>'required|pwd_rule',
                'confirm_login_pwd'=>'required',
                'safe_pwd'=>'required|pwd_rule',
                'confirm_safe_pwd'=>'required',
            ];
        }
        return [];
    }

    public function attributes()
    {
        return [
            'user_number'=>'编号',
            'real_name'=>'姓名',
            'user_phone'=>'手机号',
            'login_pwd'=>'登录密码',
            'confirm_login_pwd'=>'确登录密码',
            'safe_pwd'=>'安全密码',
            'confirm_safe_pwd'=>'确认安全密码',
        ];
    }

    public function messages()
    {
        return [
            'required'=>':attribute不能为空',
            'mobile'=>':attribute格式不正确',
            'unique'=>':attribute不能重复',
            'alpha_start'=>':attribute只能包含字母和数字',
            'pwd_rule'=>':attribute不符合规则',
        ];
    }
}
